"""
@author: xxw
@file: logset.py
@time: 2023/6/12 15:25
"""
import logging
from logging import FileHandler, StreamHandler
from logging.handlers import TimedRotatingFileHandler, RotatingFileHandler

#得到一个日志器，日志器用来记录日志
logger = logging.getLogger()

#处理器
#  输出到文件
fh = FileHandler("sc.log")
#按大小轮转
#fh = RotatingFileHandler("sc_bak.log", maxBytes=100, backupCount=2)
#按时间轮转
# fh = TimedRotatingFileHandler("sc_bak.log", when="S", interval=2, backupCount=2)

#  输出到屏幕
ch = StreamHandler()

#格式器
log_format = "%(asctime)s|%(filename)s|%(levelname)s:%(message)s"
formatter = logging.Formatter(log_format)

#绑定formatter到handler上
fh.setFormatter(formatter)

#将handler帮到logger对象上
logger.addHandler(fh)
logger.addHandler(ch)

logger.setLevel(logging.INFO)
